﻿package mortal.game.view.copy.copyFailWin
{
    import Message.Game.*;
    import __AS3__.vec.*;
    import com.greensock.*;
    import com.greensock.easing.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.display.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.palyer.data.*;
    import mortal.mvc.interfaces.*;

    public class CopyFailBaseWin extends ResultBaseWindow
    {
        private var _turnLeftBtn:GLoadedButton;
        private var _turnRightBtn:GLoadedButton;
        private var _tipsImage:GImageBitmap;
        private var _mask:ScaleBitmap;
        private var _fullMask:GSprite;
        private var _moduleBox:GSprite;
        private var _maskBox:GSprite;
        private var _tween:TweenMax;
        private var _moduleList:Vector.<CopyFailModuleRender>;
        private var _currentIndex:int = 1;
        private var _totalPage:int;
        protected var _copyTxt:GTextFiled;
        protected var _copyTip2:GImageBitmap;
        private var _titleTip:GImageBitmap;
        private var _tianDBM:GImageBitmap;
        private var _tianDTitleName:GTextFiled;
        private static var _instance:CopyFailBaseWin;

        public function CopyFailBaseWin(param1:ILayer = null)
        {
            this._moduleList = new Vector.<CopyFailModuleRender>;
            this.layer = LayerManager.topWindowLayer;
            super(param1);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._titleTip = UIFactory.gImageBitmap(ImagesConst.ResultWindowTxt_1, (this.width - 317) * 0.5, 43, this);
            this._maskBox = UICompomentPool.getUICompoment(GSprite);
            this.addChild(this._maskBox);
            this._mask = UIFactory.bg(10, 0, -1, -1, this._maskBox, ImagesConst.Forging_GemEmbedBg2);
            this._maskBox.mask = this._mask;
            this._moduleBox = UICompomentPool.getUICompoment(GSprite);
            this._maskBox.addChild(this._moduleBox);
            this._turnLeftBtn = UIFactory.gLoadedButton(ImagesConst.MountLeft_upSkin, 162, 105, 33, 37, this);
            this._turnLeftBtn.configEventListener(MouseEvent.CLICK, this.updatePage);
            this._turnRightBtn = UIFactory.gLoadedButton(ImagesConst.MountRight_upSkin, 503, 105, 33, 37, this);
            this._turnRightBtn.configEventListener(MouseEvent.CLICK, this.updatePage);
            this.resultType = ResultBaseWindow.showFail;
            setContentBgSize(370, 100);
            this.createList();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._titleTip.dispose(param1);
            this._titleTip = null;
            this._turnLeftBtn.dispose(param1);
            this._turnLeftBtn = null;
            this._turnRightBtn.dispose(param1);
            this._turnRightBtn = null;
            this._moduleBox.dispose(param1);
            this._moduleBox = null;
            this._mask.dispose(param1);
            this._mask = null;
            this._maskBox.mask = null;
            this._maskBox.dispose(param1);
            this._maskBox = null;
            if (this._tipsImage)
            {
                this._tipsImage.dispose(param1);
                this._tipsImage = null;
            }
            if (this._fullMask)
            {
                this._fullMask.dispose(param1);
                this._fullMask = null;
            }
            this._moduleList.length = 0;
            this._currentIndex = 1;
            this.clearTween();
            this._copyTxt = null;
            this._copyTip2 = null;
            this._tianDBM = null;
            this._tianDTitleName = null;
            return;
        }// end function

        override public function hide() : void
        {
            super.hide();
            if (this._fullMask)
            {
                this._fullMask.graphics.clear();
            }
            return;
        }// end function

        override protected function updateSize() : void
        {
            super.updateSize();
            if (this._maskBox)
            {
                this._maskBox.x = _contentBg.x;
                this._maskBox.y = _contentBg.y;
            }
            if (this._mask)
            {
                this._mask.width = _contentBg.width - 20;
                this._mask.height = _contentBg.height;
            }
            return;
        }// end function

        private function createList() : void
        {
            var _loc_1:CopyFailModuleRender = null;
            var _loc_3:FashionAdvanceData = null;
            var _loc_4:int = 0;
            var _loc_2:* = Cache.instance.role.entityInfo.level;
            if (GameController.autoGuide.hasGuideQH())
            {
                _loc_1 = UICompomentPool.getUICompoment(CopyFailModuleRender);
                _loc_1.setModuleType(CopyFailModuleRender.strength);
                _loc_1.moduleLevel = -1;
                this._moduleList.push(_loc_1);
            }
            if (_loc_2 >= GameDefConfig.instance.getSystemOpenLevel(28))
            {
                _loc_1 = UICompomentPool.getUICompoment(CopyFailModuleRender);
                _loc_1.setModuleType(CopyFailModuleRender.pet);
                _loc_1.moduleLevel = 0;
                this._moduleList.push(_loc_1);
            }
            if (_loc_2 >= GameDefConfig.instance.getSystemOpenLevel(13))
            {
                _loc_1 = UICompomentPool.getUICompoment(CopyFailModuleRender);
                _loc_1.setModuleType(CopyFailModuleRender.mounth);
                _loc_1.moduleLevel = Cache.instance.mount.mountData.mountLevel;
                _loc_1.clickEabled = _loc_1.moduleLevel < MountUtil.maxMountLevel;
                this._moduleList.push(_loc_1);
            }
            if (_loc_2 >= GameDefConfig.instance.getSystemOpenLevel(66))
            {
                _loc_1 = UICompomentPool.getUICompoment(CopyFailModuleRender);
                _loc_1.setModuleType(CopyFailModuleRender.fashion);
                _loc_3 = Cache.instance.fashion.getFashionInfo(EFashionType._EFashionClothes);
                _loc_1.moduleLevel = _loc_3.advanceInfo.code;
                _loc_1.clickEabled = _loc_1.moduleLevel < FashionConst.FashionAdvanceMaxLevel;
                this._moduleList.push(_loc_1);
            }
            if (_loc_2 >= GameDefConfig.instance.getSystemOpenLevel(67))
            {
                _loc_1 = UICompomentPool.getUICompoment(CopyFailModuleRender);
                _loc_1.setModuleType(CopyFailModuleRender.wing);
                _loc_3 = Cache.instance.fashion.getFashionInfo(EFashionType._EFashionWing);
                _loc_1.moduleLevel = _loc_3.advanceInfo.code;
                _loc_1.clickEabled = _loc_1.moduleLevel < FashionConst.FashionAdvanceMaxLevel;
                this._moduleList.push(_loc_1);
            }
            if (_loc_2 >= GameDefConfig.instance.getSystemOpenLevel(68))
            {
                _loc_1 = UICompomentPool.getUICompoment(CopyFailModuleRender);
                _loc_1.setModuleType(CopyFailModuleRender.weapon);
                _loc_3 = Cache.instance.fashion.getFashionInfo(EFashionType._EFashionWeapon);
                _loc_1.moduleLevel = _loc_3.advanceInfo.code;
                _loc_1.clickEabled = _loc_1.moduleLevel < FashionConst.FashionAdvanceMaxLevel;
                this._moduleList.push(_loc_1);
            }
            this._moduleList.sort(this.sortRender);
            while (_loc_4 < this._moduleList.length)
            {
                
                _loc_1 = this._moduleList[_loc_4];
                _loc_1.x = 110 * _loc_4 + 25;
                _loc_1.y = 17;
                this._moduleBox.addChild(_loc_1);
                this.pushUIToDisposeVec(_loc_1);
                _loc_4++;
            }
            this._totalPage = Math.ceil(this._moduleList.length / 3);
            this.updateBtn();
            return;
        }// end function

        private function sortRender(param1:CopyFailModuleRender, param2:CopyFailModuleRender) : int
        {
            if (param1.moduleLevel > param2.moduleLevel)
            {
                return 1;
            }
            if (param1.moduleLevel < param2.moduleLevel)
            {
                return -1;
            }
            return 0;
        }// end function

        private function updatePage(event:MouseEvent = null) : void
        {
            if (this._tween && this._tween.active)
            {
                return;
            }
            if (event.target == this._turnLeftBtn)
            {
                var _loc_2:String = this;
                var _loc_3:* = this._currentIndex - 1;
                _loc_2._currentIndex = _loc_3;
                this._tween = TweenMax.to(this._moduleBox, 0.5, {x:this._moduleBox.x + 110 * 3, ease:Back.easeOut});
            }
            else if (event.target == this._turnRightBtn)
            {
                var _loc_2:String = this;
                var _loc_3:* = this._currentIndex + 1;
                _loc_2._currentIndex = _loc_3;
                this._tween = TweenMax.to(this._moduleBox, 0.5, {x:this._moduleBox.x - 110 * 3, ease:Back.easeOut});
            }
            this.updateBtn();
            return;
        }// end function

        private function updateBtn() : void
        {
            this._turnLeftBtn.filterEnabled = this._currentIndex > 1;
            this._turnRightBtn.filterEnabled = this._currentIndex < this._totalPage;
            return;
        }// end function

        protected function get darkMask() : GSprite
        {
            if (this._fullMask == null)
            {
                this._fullMask = UICompomentPool.getUICompoment(GSprite);
            }
            return this._fullMask;
        }// end function

        override public function stageResize() : void
        {
            super.stageResize();
            if (this.darkMask != null)
            {
                this.darkMask.cacheAsBitmap = true;
                DisplayUtil.drawFullScreenMask(this.darkMask);
            }
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            (layer as DisplayObjectContainer).addChild(this.darkMask);
            this.stageResize();
            super.show(param1, param2);
            return;
        }// end function

        private function clearTween() : void
        {
            if (this._tween)
            {
                this._tween.kill();
                this._tween = null;
            }
            return;
        }// end function

        protected function loadTitleComplete() : void
        {
            if (this.isDisposed)
            {
                return;
            }
            this._tipsImage.x = (this.width - this._tipsImage.width) * 0.5;
            this._tipsImage.y = 155;
            return;
        }// end function

        public function set tipsImageUrl(param1:String) : void
        {
            if (this._tipsImage == null)
            {
                this._tipsImage = UIFactory.gImageBitmap("", 0, 0, this);
            }
            this._tipsImage.onLoadCompl = this.loadTitleComplete;
            this._tipsImage.imgUrl = param1;
            return;
        }// end function

        public function defenseCopy(param1:int) : void
        {
            resultType = showSuccess;
            if (this._copyTxt == null)
            {
                this._copyTxt = UIFactory.gTextField("" + Language.getString(71394), 245, 177, 300, 30, this, GlobalStyle.textFormatLv.setSize(15).setBold(true));
            }
            if (this._copyTip2 == null)
            {
                this._copyTip2 = UIFactory.gImageBitmap(ImagesConst.copyFailBaseWinTxt_0, 173, 207, this);
            }
            return;
        }// end function

        public function tianDiShow(param1:String) : void
        {
            this._titleTip.visible = false;
            if (this._tianDBM == null)
            {
                this._tianDBM = UIFactory.gImageBitmap(ImagesConst.TianDiPassFaildTitleDes, 70, 37, this);
            }
            if (this._tianDTitleName == null)
            {
                this._tianDTitleName = UIFactory.gTextField(param1, 261, 45, 160, 25, this, GlobalStyle.textFormatZi.setSize(15).center().setBold(true));
            }
            return;
        }// end function

        public static function get instance() : CopyFailBaseWin
        {
            if (_instance == null)
            {
                _instance = new CopyFailBaseWin;
            }
            return _instance;
        }// end function

    }
}
